let list = null

async function get() {
  list = await axios({
    url: 'index/index',
  }).then(res => {
    console.log(res.data.data)
    return res.data.data
  })
  new Vue({
    el: '.shw',
    data: {
      allCate: list.allCate,
      banner: list.banner,
      sideBanner: list.sideBanner,
      allTag: list.allTag,
      allLink: list.allLink,
      token: localStorage.getItem('token'),
      user: JSON.parse(localStorage.getItem('user')),
      pic: null,
      title: '',
      cateid: 0,
      tags: [],
      content: '',
    },
    filters: {
      www(val) {
        let day = new Date(val).getDate()
        day = day < 10 ? '0' + day : day
        let m = new Date(val).getMonth() + 1
        m = m < 10 ? '0' + m : m
        let y = new Date(val).getFullYear()
        y = y < 10 ? '0' + y : y
        return y + '-' + m + '-' + day
      },
    },
    conputed: {},
    // http://124.223.14.236:8060/
    methods: {
      postTxt(satus) {
        // console.log(this.pic)
        // console.log(this.title)
        // console.log(this.user.userInfo.username)
        // console.log(this.cateid)
        // console.log(String(this.tags))
        // console.log(this.content)
        // return
        axios({
          method: 'post',
          url: 'user/addArticle',
          headers: { token: localStorage.getItem('token') },
          data: {
            title: this.title,
            author: this.user.userInfo.username,
            cateid: this.cateid,
            tags: String(this.tags),
            pic: this.pic,
            content: this.content,
            status: satus,
          },
        }).then(res => {
          console.log(res)
        })
      },
      back() {
        location.href = '/web-static/user.html'
      },
      change(e) {
        console.log(e.target.files[0])
        let fd = new FormData()
        fd.append('file', e.target.files[0])
        axios({
          method: 'POST',
          data: fd,
          url: 'common/upload?type=images',
          headers: { token: localStorage.getItem('token') },
        }).then(res => {
          console.log(res.data.data.savePath)
          this.pic = res.data.data.savePath
        })
      },
      poosPic() {
        this.$refs.file.click()
      },
      fy(e) {
        if (e.target.localName === 'a' || e.taget.localName === em) {
          this.newIndex = newIndex
        }
      },
      rem() {
        layer.confirm(
          '确认退出？',
          {
            btn: ['确认', '取消'], //可以无限个按钮
          },
          function (index, layero) {
            //按钮【按钮一】的回调
            localStorage.clear()
            location.href = '/web-static/index.html'
          },
          function (index) {
            //按钮【按钮二】的回调
          },
        )
      },
    },
  })
}
get()
axios({
  url: 'user/getUserInfo',
  headers: { token: localStorage.getItem('token') },
}).then(res => {
  localStorage.setItem('user', JSON.stringify(res.data.data))
})
